<template>
  <div v-loading="loading" class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('还款计划') }}</span>
    </div>
    <el-form v-if="queryPramsHidden" ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('项目名称')" prop="dealName">
        <el-input
          v-model="queryParams.dealName"
          :placeholder="$t('项目名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('预计还款时间')">
        <DatePicker
          v-model="newDateRange"
          type="daterange"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
        <el-button
          v-hasPermi="['deal:planreport:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t("导出") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目名称')" align="center" prop="dealName" show-overflow-tooltip>
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/deal/home/dealBaseHome',query:{id:scope.row.dealId,companyId:scope.row.companyId}}"
            class="link_a"
          >{{ scope.row.dealName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('投资主体')" align="center" prop="investmentName" />
      <el-table-column :label="$t('还款类型')" align="center" prop="type" :formatter="typeFormat" />
      <el-table-column :label="$t('预计还款日期')" align="center" prop="expectDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expectDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('预计还款金额') + $t('金额单位')" align="center" prop="expectMoney" width="180">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.expectMoney, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('实际还款日期')" align="center" prop="actualDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('实际还款金额') + $t('金额单位')" align="center" prop="actualMoney" width="180">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.actualMoney, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" width="80">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['payment:report:view']"
            size="small"
            type="text"
            icon="el-icon-view"
            @click="viewHandle(scope.row)"
          >{{ $t('查看') }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改合同信息对话框 -->
    <el-dialog :title="title" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" append-to-body custom-class="dialogForm">
      <dealServicingPlanForm ref="dealServicingPlanForm" :btn-show="false" />
    </el-dialog>
  </div>
</template>

<script>
import { findLatestServicingPlan } from '@/api/deal/servicing/dealServicingPlan'
import dealServicingPlanForm from '@/views/deal/servicing/dealServicingPlanForm'
import { downLoadExcel } from '@/utils/excelDownload'
export default {
  components: { dealServicingPlanForm },
  props: {
    dateRange: {
      type: Array,
      default: undefined,
      desc: '日期范围'
    },
    queryPramsHidden: {
      type: Boolean,
      default: true,
      desc: '是否隐藏查询条件'
    }
  },
  data() {
    return {
      dataList: [],
      // 遮罩层
      loading: false,
      // 查询参数
      queryParams: {
        dealName: undefined,
        pageNum: 1,
        pageSize: 10
      },
      total: 0,
      formOpen: false,
      title: this.$t('还款计划'),
      typeOptions: [],
      newDateRange: []
    }
  },
  watch: {
    dateRange: {
      handler(val) {
        this.newDateRange = val
      },
      deep: true
    }
  },
  created() {
    this.getList()
    this.getDicts('servicing_plan_type').then(response => {
      this.typeOptions = response.data
    })
  },
  methods: {
    getList() {
      this.loading = true
      findLatestServicingPlan(this.addDateRange(this.queryParams, this.newDateRange)).then(response => {
        this.dataList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.newDateRange = undefined
      this.queryHandle()
    },
    // 币种 字典翻译
    currencyFormat(row) {
      return this.selectDictLabel(this.currencyOptions, row.currency)
    },
    viewHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.dealServicingPlanForm.init(row)
      })
    },
    // 还款类型 字典servicing_plan_type字典翻译
    typeFormat(row) {
      return this.selectDictLabel(this.typeOptions, row.type)
    },
    exportHandle() {
      downLoadExcel('/plan/dealServicingPlan/findLatestServicingPlan/exportReport', this.queryParams)
    }
  }
}
</script>

<style scoped>

</style>
